
c	Created: Tuesday, August 13, 1991 at 4:31 PM
c	 ImageCompression.p
c	 Pascal Interface to the Macintosh Libraries
	
c	 Copyright Apple Computer, Inc. 1991
c	 All rights reserved
	
	
	
!!IFC UNDEFINED UsingIncludes
!!SETC UsingIncludes = False
!!ENDC
	
!!IFC NOT UsingIncludes
!!I ZEROINC.F
!!ENDC

!!IFC NOT GotImageCompression
!!SETC GotImageCompression = True
	
!!IFC Not GotQuickDraw
!!I QuickDraw.f
!!ENDC
!!IFC not GotQDOffscreen
!!I QDOffscreen.f
!!ENDC
!!IFC not GotTypes
!!I Types.f
!!ENDC
!!IFC not GotComponents
!!I Components.f
!!ENDC
!!IFC not GotStandardFile
!!I StandardFile.f
!!ENDC
	
	Character*4 gestaltCompressionMgr
	Parameter (gestaltCompressionMgr = 'icmp')
	
c These are the bits that are set in the Component flags, and also in the codecInfo struct. 
	
	Integer*4 codecInfoDoes1  
	Integer*4 codecInfoDoes2  
	Integer*4 codecInfoDoes4  
	Integer*4 codecInfoDoes8  
	Integer*4 codecInfoDoes16  
	Integer*4 codecInfoDoes32  
	Integer*4 codecInfoDoesDither  
	Integer*4 codecInfoDoesStretch  
	Integer*4 codecInfoDoesShrink  
	Integer*4 codecInfoDoesMask  
	
	Integer*4 codecInfoDoesTemporal  
	
	Integer*4 codecInfoDoesDouble  
	Integer*4 codecInfoDoesQuad  
	Integer*4 codecInfoDoesHalf  
	Integer*4 codecInfoDoesQuarter  
	
	Integer*4 codecInfoDoesRotate  
	Integer*4 codecInfoDoesHorizFlip  
	Integer*4 codecInfoDoesVertFlip  
	Integer*4 codecInfoDoesSkew  
	Integer*4 codecInfoDoesBlend  
	Integer*4 codecInfoDoesWarp 
	Integer*4 codecInfoDoesRecompress 
	Integer*4 codecInfoDoesSpool 
	
	Parameter (codecInfoDoes1 = $1)			! codec can work with 1-bit pixels 
	Parameter (codecInfoDoes2 = $2)			! codec can work with 2-bit pixels 
	Parameter (codecInfoDoes4 = $4)			! codec can work with 4-bit pixels 
	Parameter (codecInfoDoes8 = $8)			! codec can work with 8-bit pixels 
	Parameter (codecInfoDoes16 = $10)		! codec can work with 16-bit pixels 
	Parameter (codecInfoDoes32 = $20)		! codec can work with 32-bit pixels 
	Parameter (codecInfoDoesDither = $40)	! codec can do ditherMode 
	Parameter (codecInfoDoesStretch = $80)	! codec can stretch to arbitrary sizes 
	Parameter (codecInfoDoesShrink = $100)	! codec can shrink to arbitrary sizes 
	Parameter (codecInfoDoesMask = $200)	! codec can mask to clipping regions 
	
	Parameter (codecInfoDoesTemporal = $400)! codec can handle temporal redundancy 
	
	Parameter (codecInfoDoesDouble = $800)	! codec can stretch to double size exactly 
	Parameter (codecInfoDoesQuad = $1000)	! codec can stretch to quadruple size exactly 
	Parameter (codecInfoDoesHalf = $2000)	! codec can shrink to half size 
	Parameter (codecInfoDoesQuarter = $4000)! codec can shrink to quarter size 
	
	Parameter (codecInfoDoesRotate = $8000)	! codec can rotate on decompress 
	Parameter (codecInfoDoesHorizFlip = $10000)	! codec can flip horizontally on decompress 
	Parameter (codecInfoDoesVertFlip = $20000)	! codec can flip vertically on decompress 
	Parameter (codecInfoDoesSkew = $40000)	! codec can skew on decompress 
	Parameter (codecInfoDoesBlend = $80000)	! codec can blend on decompress 
	Parameter (codecInfoDoesWarp = $100000)	! codec can warp arbitrarily on decompress 
	Parameter (codecInfoDoesRecompress = $200000)! codec can recompress image without accumulating errors 
	Parameter (codecInfoDoesSpool = $400000)! codec can spool image data 
	
	Integer*4  codecInfoDepth1  
	Integer*4  codecInfoDepth2  
	Integer*4  codecInfoDepth4  
	Integer*4  codecInfoDepth8  
	Integer*4  codecInfoDepth16  
	Integer*4  codecInfoDepth32  
	Integer*4  codecInfoDepth24  
	Integer*4  codecInfoDepth33  
	Integer*4  codecInfoDepth34  
	Integer*4  codecInfoDepth36  
	Integer*4  codecInfoDepth40  
	Integer*4  codecInfoStoresClut  
	Integer*4  codecInfoDoesLossless  

	Parameter (codecInfoDepth1 = $1) ! compressed data at 1 bpp depth available 
	Parameter (codecInfoDepth2 = $2) ! compressed data at 2 bpp depth available 
	Parameter (codecInfoDepth4 = $4) ! compressed data at 4 bpp depth available 
	Parameter (codecInfoDepth8 = $8) ! compressed data at 8 bpp depth available 
	Parameter (codecInfoDepth16 = $10) ! compressed data at 16 bpp depth available 
	Parameter (codecInfoDepth32 = $20) ! compressed data at 32 bpp depth available 
	Parameter (codecInfoDepth24 = $40) ! compressed data at 24 bpp depth available 
	Parameter (codecInfoDepth33 = $80) ! compressed data at 1 bpp monochrome depth  available 
	Parameter (codecInfoDepth34 = $100) ! compressed data at 2 bpp grayscale depth available 
	Parameter (codecInfoDepth36 = $200) ! compressed data at 4 bpp grayscale depth available 
	Parameter (codecInfoDepth40 = $400) ! compressed data at 8 bpp grayscale depth available 
	Parameter (codecInfoStoresClut = $800) ! compressed data can have custom cluts 
	Parameter (codecInfoDoesLossless = $1000) ! compressed data can be stored in lossless format 
	
	Integer*4 codecFlagUseImageBuffer 
	Integer*4 codecFlagUseScreenBuffer  
	Integer*4 codecFlagUpdatePrevious  
	Integer*4 codecFlagNoScreenUpdate  
	Integer*4 codecFlagWasCompressed  
	Integer*4 codecFlagDontOffscreen  
	Integer*4 codecFlagUpdatePreviousComp  
	Integer*4 codecFlagForceKeyFrame  
	Integer*4 codecFlagOnlyScreenUpdate  
	Integer*4 codecFlagLiveGrab	 
	
	Parameter (codecFlagUseImageBuffer = $1) ! (input) allocate buffer for whole image on decompress sequence 
	Parameter (codecFlagUseScreenBuffer = $2) ! (input) allocate buffer for screen on decompress sequence for faster updates 
	Parameter (codecFlagUpdatePrevious = $4) ! (input) udate previous buffer on compress sequence 
	Parameter (codecFlagNoScreenUpdate = $8) ! (input) dont update screen, but do update image buffer If (allocated 
	Parameter (codecFlagWasCompressed = $10) ! (input) hint to compressor that image was previously compressed 
	Parameter (codecFlagDontOffscreen = $20) ! (input) return error instead of automatically going offscreen 
	Parameter (codecFlagUpdatePreviousComp = $40) ! (input) udate previous buffer on compress sequence 
	Parameter (codecFlagForceKeyFrame = $80) ! (input) when sent to CompressSequenceFrame, forces that frame to be a key frame 
	Parameter (codecFlagOnlyScreenUpdate = $100) ! (input) only update screen from 
	Parameter (codecFlagLiveGrab	= $200) ! (input) data being compressed is from live source (speed is critical) 
		
	Integer*4 codecFlagUsedNewImageBuffer	 
	Integer*4 codecFlagUsedImageBuffer  
	
	Parameter (codecFlagUsedNewImageBuffer	= $4000) ! (output) indicates that image buffer was first used on this decompress sequence 
	Parameter (codecFlagUsedImageBuffer = $8000) ! (output) indicates that image buffer was used on this decompress sequence 

	Integer*2  codecErr  
	Integer*2  noCodecErr  
	Integer*2  codecUnimpErr  
	Integer*2  codecSizeErr  
	Integer*2  codecScreenBufErr  
	Integer*2  codecImageBufErr  
	Integer*2  codecSpoolErr  
	Integer*2  codecAbortErr  
	Integer*2  codecWouldOffscreenErr  
	Integer*2  codecBadDataErr  
	Integer*2  codecDataVersErr  
	Integer*2  codecConditionErr  
	Integer*2  codecOpenErr  
	
	Parameter (codecErr = -8960	) ! the codec returned an error 
	Parameter (noCodecErr = -8961) ! the specified codec could not be found 
	Parameter (codecUnimpErr = -8962) ! this feature is not implemented by the specified codec 
	Parameter (codecSizeErr = -8963)
	Parameter (codecScreenBufErr = -8964) ! the screen buffer could not be allocated 
	Parameter (codecImageBufErr = -8965) ! the image buffer could not be allocated 
	Parameter (codecSpoolErr = -8966) ! the compressed data must be in memory (spooling did not work) 
	Parameter (codecAbortErr = -8967) ! the operation was aborted by the progress proc 
	Parameter (codecWouldOffscreenErr = -8968) ! an offscreen access would have been used, but wasn't allowed because codecFlagDontOffscreen was set 
	Parameter (codecBadDataErr = -8969) ! compressed data was found to have inconsistencies 
	Parameter (codecDataVersErr = -8970) ! compressed data was of a format version that codec couldn't handle 
	Parameter (codecConditionErr = -8972) ! codec can not do requested operation 
	Parameter (codecOpenErr = -8973	) ! the codec  could not be opened 
	
	Integer*2  codecMinimumDataSize  
	
	Character*4 compressorComponentType  
	Character*4 decompressorComponentType  
	
	Parameter (codecMinimumDataSize = 32768) ! The minimum data size for spooling in or out data 
	
	Parameter (compressorComponentType = 'imco') ! the type for "Components" which compress images 
	Parameter (decompressorComponentType = 'imdc') ! the type for "Components" which decompress images 
	
	Integer*2 codecLosslessQuality	
	Integer*2 codecMaxQuality			
	Integer*2 codecMinQuality			
	Integer*2 codecLowQuality			
	Integer*2 codecNormalQuality		
	Integer*2 codecHighQuality		
	
	Parameter (codecLosslessQuality	= $400)
	Parameter (codecMaxQuality			= $3FF)
	Parameter (codecMinQuality			= $000)
	Parameter (codecLowQuality			= $100)
	Parameter (codecNormalQuality		= $200)
	Parameter (codecHighQuality		= $300)
	
	Integer*2 anyCodec 				
	Integer*2 bestSpeedCodec 			
	Integer*2 bestFidelityCodec		
	Integer*2 bestCompressionCodec	
	
	Parameter (anyCodec 				=  0)		! take first working codec of given type 
	Parameter (bestSpeedCodec 			= -1)		! take fastest codec of given type 
	Parameter (bestFidelityCodec		= -2)		! take codec which is most accurate
	Parameter (bestCompressionCodec	= -3)			! take codec of given type that is most accurate 
	
	Integer*2 codecCompletionSource 
	Integer*2 codecCompletionDest 
	
	Integer*2 codecProgressOpen 
	Integer*2 codecProgressUpdatePercent 
	Integer*2 codecProgressClose 
	
	Parameter (codecCompletionSource = 1)			! asynchronous codec is done with source data  
	Parameter (codecCompletionDest = 2)				! asynchronous codec is done with destination data  
	
	Parameter (codecProgressOpen = 0)
	Parameter (codecProgressUpdatePercent = 1)
	Parameter (codecProgressClose = 2)
	
	Integer*2 identityMatrixType			
	Integer*2 translateMatrixType		
	Integer*2 scaleMatrixType			
	Integer*2 scaleTranslateMatrixType	
	Integer*2 linearMatrixType			
	Integer*2 linearTranslateMatrixType	
	Integer*2 perspectiveMatrixType		

	Integer*2 sfpItemPreviewAreaUser 
	Integer*2 sfpItemPreviewStaticText 
	Integer*2 sfpItemPreviewDividerUser 
	Integer*2 sfpItemCreatePreviewButton 
	Integer*2 sfpItemShowPreviewButton 
		
	Parameter (identityMatrixType		= $00) ! result If (matrix is identity 
	Parameter (translateMatrixType		= $01) ! result If (matrix translates 
	Parameter (scaleMatrixType			= $02) ! result If (matrix scales 
	Parameter (scaleTranslateMatrixType	= $03) ! result If (matrix scales and translates 
	Parameter (linearMatrixType			= $04) ! result If (matrix is general 2 x 2 
	Parameter (linearTranslateMatrixType = $05) ! result If (matrix is general 2 x 2 and translates 
	Parameter (perspectiveMatrixType	= $06) ! result If (matrix is general 3 x 3 

	Parameter (sfpItemPreviewAreaUser = 11)
	Parameter (sfpItemPreviewStaticText = 12)
	Parameter (sfpItemPreviewDividerUser = 13)
	Parameter (sfpItemCreatePreviewButton = 14)
	Parameter (sfpItemShowPreviewButton = 15)
		
	
c	CompressorComponent = Component		! a Component which compresses images 
c	DecompressorComponent = Component	! a Component which decompresses images 
c	CodecComponent = Component			! a Component which decompresses or compresses images 

c	The following types are equivalent	
c	sBoolean is the same as INTEGER*2		! to make sure stack frames are right 	
c	CodecType is the same as OSTYPE			! type descriptor for codecs i.e: 'appl','jpeg','rle ' 	
c	CodecFlags is the same as INTEGER*2		! flags for codec manager calls 
	
c	CodecQ is the same as Integer*4
c	DataProcPtr is the same as ProcPtr
c	FlushProcPtr is the same as ProcPtr
c	CompletionProcPtr is the same as ProcPtr
c	ProgressProcPtr is the same as ProcPtr
c	ImageSequence is the same as Integer*4 
c	 MatrixFlags = CHAR
	
	
	Structure /ProgressProcRecord/
		Record /ProcPtr/ progressProc
		Integer*4 progressRefCon
	End Structure

	Structure /ProgressProcRecordPtr/
		pointer /ProgressProcRecord/ P
	End Structure

	Structure /CompletionProcRecord/
		Record /ProcPtr/ completionProc
		Integer*4 completionRefCon
	End Structure

	Structure /CompletionProcRecordPtr/
		pointer /CompletionProcRecord/ P
	End Structure

	Structure /DataProcRecord/
		Record /ProcPtr/ dataProc
		Integer*4 dataRefCon
	End Structure

	Structure /DataProcRecordPtr/
		pointer /DataProcRecord/ P
	End Structure

	Structure /FlushProcRecord/
		Record /ProcPtr/ flushProc
		Integer*4 flushRefCon
	End Structure

	Structure /FlushProcRecordPtr/
		pointer /FlushProcRecord/ P
	End Structure

c	The ImageDescription is private data which is produced when an image or sequence 
c	is compressed. It fully describes the format of the compressed data.
	
	Structure /ImageDescription/
		Integer*4  idSize				! total size of ImageDescription including extra data ( CLUTs and other per sequence data 
		Record /OSType/ cType		! what kind of codec compressed this data 
		Integer*4  resvd1				! reserved for apple use 
		Integer*2  resvd2				! reserved for apple use 
		Integer*2  dataRefIndex			! set to zero 
		Integer*2  version				! which version is this data 
		Integer*2  revisionLevel		! what version of that codec did this 
		Integer*4 vendor				! whose  codec compressed this data 
	 	Integer*4 temporalQuality	! what was the temporal quality factor          
		Integer*4 spatialQuality	! what was the spatial quality factor          
		Integer*2  width				! how many pixels wide is this data 
		Integer*2  height				! how many pixels high is this data 
		Integer*4 hRes					! horizontal resolution 
		Integer*4 vRes					! vertical resolution 
		Integer*4 dataSize				! If known, the size of data for this image descriptor 
		Integer*2  frameCount			! number of frames this description applies to 
		Character*1 name(0:31)			! name of codec ( in case not installed ) 
		Integer*2  depth				! what depth is this data (1-32) or ( 33-40 grayscale ) 
		Integer*2  clutID				! clut id or If (0 clut follows  or -1 If (no clut 
	End Structure

	Structure /ImageDescriptionPtr/
		pointer /ImageDescription/ P
	End Structure

	Structure /ImageDescriptionHandle/
		pointer /ImageDescriptionPtr/ H
	End Structure

c	The codecInfo is the information returned as the codecInfo struct by a codec Component
c	to the codec manager or to the caller. It is specific to the particular codec
c   implementation and not to the codec type.
	
	Structure /codecInfo/
	 Character*1 typename(0:31)		! name of the codec type i.e.: 'Apple Image Compression' 
	 Integer*2  version				! version of the codec data that this codec knows about 
	 Integer*2  revisionLevel		! revision level of this codec i.0x00010001 e: (1.0.1) 
	 Integer*4 vendor				! Maker of this codec i. e: appl' 
	 Integer*4 decompressFlags		! Parameter (codecInfo flags for decompression capabilities 
	 Integer*4 compressFlags		! Parameter (codecInfo flags for compression capabilities 
	 Integer*4 formatFlags			! Parameter (codecInfo flags for compression format details 
	 BYTE compressionAccuracy		! measure (1-255) of accuracy of this codec for compress (0 If (unknown) 
	 BYTE decompressionAccuracy		! measure (1-255) of accuracy of this codec for decompress (0 If (unknown) 
	 Integer*2  compressionSpeed	! ( millisecs for compressing 320x240 on base mac II) (0 If (unknown) 
	 Integer*2  decompressionSpeed	! ( millisecs for decompressing 320x240 on mac II)(0 If (unknown) 
	 Byte compressionLevel			! measure (1-255) of compression level of this codec (0 If (unknown) 
	 Byte resvd						! pad 
	 Integer*2  minimumHeight		! minimum height of image (block size) 
	 Integer*2  minimumWidth		! minimum width of image (block size) 
	 Integer*2  decompressPipelineLatency! in milliseconds ( for asynchronous codecs ) 
	 Integer*2  compressPipelineLatency	! in milliseconds ( for asynchronous codecs ) 
	 Integer*4 privateData
	End Structure
	
	Structure /DitherTable/	! Table used for fast dithering. 
	 Integer*4 tag
	 Integer*4 seed
	 Integer*4 reserved
	 Byte data(0:0)
	End Structure

	Structure /DTabPtr/
		pointer /DitherTable/ P
	End Structure

	Structure /DTabHandle/
		pointer /DTabPtr/ H
	End Structure
	
	Structure /CodecNameSpec/	! Name list returned by GetCodecNameList.
		Record /Component/ codec
		Record /OSType/ cType
		Character*1 typeName(0:31)
		Record /Handle/ name 
	End Structure
	
	Structure /CodecNameSpecList/
	 Integer*2 count
	 Record /CodecNameSpec/ list(0:0)
	End Structure

	Structure /CodecNameSpecListPtr/
		pointer /CodecNameSpecList/ P
	End Structure

	Structure /MatrixRecord/	!  Matrix stuff 
	 Integer*4 matrix(0:2,0:2)
	End Structure

	Structure /MatrixRecordPtr/
		pointer /MatrixRecord/ P
	End Structure

	Structure /FixedPoint/
	 Integer*4 x
	 Integer*4 y
	End Structure

	Structure /FixedRect/
	 Integer*4  left
	 Integer*4 top
	 Integer*4 right
	 Integer*4 bottom
	End Structure

	Structure /PreviewResourceRecord/
		Integer*4 modDate
		Integer*2 version
		RECORD /OSType/ resType
		Integer*2 resID
	End Structure

	Structure /PreviewResourcePtr/
		pointer /PreviewResourceRecord/ P
	End Structure

	Structure /PreviewResourceHandle/
		pointer /PreviewResourcePtr/ H
	End Structure
	
!!ENDC ! GotImageCompression 
	